home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4192 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  40 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!eskimo!scs
  3. From: scs@eskimo.com (Steve Summit)
  4. Subject: Re: Basic Question on SWITCH
  5. X-Nntp-Posting-Host: eskimo.com
  6. Message-ID: <DM5qor.9G1@eskimo.com>
  7. Sender: news@eskimo.com (News User Id)
  8. Organization: schmorganization
  9. References: <4e8p6m$n8q@ns.RezoNet.NET> <TANMOY.96Jan26162346@qcd.lanl.gov> <4ehfuj$166g@ns.RezoNet.NET>
  10. Date: Fri, 2 Feb 1996 16:48:26 GMT
  11.  
  12. In article <4ehfuj$166g@ns.RezoNet.NET>, ray@ultimate-tech.com
  13. (Ray Dunn) writes:
  14. >[Tanmoy Bhattacharya and/or Ari Lukumies had written:]
  15. >> A special case for digits:
  16. >>    if ((unsigned)(a-'0')<10)
  17. >>       /* It _is_ a digit, do something */
  18. >> But then what is wrong with isdigit?
  19. > Indeed.  In the general case there is no guarantee that all the digits 
  20. > are consecutive as they are in ASCII, so the use of isdigit is the only 
  21. > portable way to go...
  22.  
  23. Actually, it turns out that there *is* a guarantee that the
  24. digits are consecutive, and it's in about the highest authority
  25. possible: the ANSI/ISO Standard (section 2.2.1 in the old ANSI
  26. version).  It's true that you rarely need to make use of this
  27. guarantee when testing for digits, because isdigit() is usually a
  28. better choice, but it makes it *much* easier to write anything
  29. that has to convert number strings to numbers (a la atoi),
  30. because there isn't a standard ctod() or digit_weight() function.
  31.  
  32. (What's true is that the *letters* aren't guaranteed to be
  33. consecutive, as they aren't in EBCDIC.  So be careful when you're
  34. writing strtol, although for A-F I think you're safe in EBCDIC,
  35. too.)
  36.  
  37.                     Steve Summit
  38.                     scs@eskimo.com
  39.